<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
use Throwable;

class FetchContractDocumentJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public string $applyNo;

    public function __construct(string $applyNo)
    {
        $this->applyNo = $applyNo;
    }

    public function handle(): void
    {
        try {
            Artisan::call('contract:fetch-document', [
                'apply_no' => $this->applyNo,
            ]);
        } catch (Throwable $exception) {
            Log::error('[ContractSign][Job] Fetch contract document failed', [
                'apply_no' => $this->applyNo,
                'error' => $exception->getMessage(),
            ]);

            throw $exception;
        }
    }
}
